/*
Copyright (C) 2021-2025 Casa Xu (also Zhiyan Xu) from HIT

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

/*
 * LOS_SunSensor.h
 *
 *  Created on: 2023年2月12日
 *      Author: 64435
 */

#ifndef PERIPHERAL_LAYER_INC_LOS_SUNSENSOR_H_
#define PERIPHERAL_LAYER_INC_LOS_SUNSENSOR_H_

#include "LOS_SYS.h"

extern uint8_t TMPACK_SUNSBasic[26];
//extern uint8_t TMPACK_SUNSImage[280];

typedef struct LOS_SUNSSTA_t
{
    /* 健康管理状态量 */
    uint8_t VAL;                 //数据有效性标志，0：有效， 其他值：无效
    uint8_t CMD;                 //开关机指令状态,发送开机指令后置1，发送关机指令后置0
    uint8_t PWR;                 //电源状态，读取电源遥测，通电为1，断电为0
    uint8_t MSG;                 //通信状态，通信正常为0，通信异常为其他值
    uint8_t RBCNT;               //复位次数
    uint8_t NFR;                 //Need For Reset 需要复位标志位，1为需要复位，0为不需要
    uint8_t RBT_F;              //表示单机是否处于重启过程中 0：未处于 1：处于重启过程中
    uint8_t RECOV;               //恢复计数：单机重启完成后，需要等待一段时间才能再次进入重启流程，将该计数置于某一值开始倒计时，倒计时结束后会再次开始判断是否需要重启
    uint8_t REC;                //CAN识别标志位,0:未识别  1：识别
    uint8_t HL_TXF;              //HL_前缀表示健康管理相关变量。遥测请求发送完成标志,发送一次后该量置1，接收到回应后置0(TX FINISHED)
    uint8_t HL_WCNT;             //等待接收计数器。该计数器在操作系统的一个线程中累加，当HL_TXF为1时该值+1，HL_TXF为0时该值清0，当累加到一定值时系统会判断通信异常，并将MSG置1
    uint32_t TMCNT;
    uint16_t FlagF_CNT;         //物理量异常重启计数
    uint16_t FlagT_CNT;         //通信异常重启计数
    uint16_t FlagY_CNT;    
    /* 太敏工程参数 */
    uint8_t sta;                 //bit7:工作是否正常0失效1正常 bit6:是否超视场0是1否 bit5:参数修改标记0未改1已改 bit4:增益标记0低1高 bit3~0光点个数
    uint8_t Attitude_Delay;      //姿态延时
    uint8_t Normalized_Threshold;//归一化阈值
    uint8_t Exposure_Time;       //曝光时间
    uint8_t OverSight;           //超视场标记
    double alpha;                //alpha角
    float alpha_deg;
    double beta;                 //beta角
    float beta_deg;
    uint8_t Flag_D;              //AOCS的FlagD
    uint8_t Flag_M;
}LOS_SUNSSTA_t;

typedef struct LOS_SUNSTEST_t
{
    uint8_t angsel;    //太阳角选择：0：不改变/恢复  1：alpha角 2:beta角 3：开始作用
    float alpha_upt;   
    float beta_upt;
    uint8_t ossel;    //太阳角选择：0：不改变/恢复  1：开始作用
    uint8_t OverSight_upt;  //超视场标记，0：超视场
}LOS_SUNSTEST_t;

extern LOS_SUNSSTA_t STA_SUNS;
LOS_SUNSTEST_t TEST_SUNS;

void LOS_SunSensor_Set(uint8_t cmd1, uint8_t cmd2);
void LOS_SunSensor_GetSta();
void LOS_SunSensor_GetImage();
void LOS_SUNS_PWROn();
void LOS_SUNS_PWROff();
void LOS_CAN_SunSensorCallBack(LOS_CANMSG_t* can_re);


#endif /* PERIPHERAL_LAYER_INC_LOS_SUNSENSOR_H_ */
